﻿using System;

namespace Affinity.Core.Messages
{
    public class Channel<TMessage> : IReadableWritableChannel<TMessage>
    {
        public void SendMessage(TMessage message)
        {
            if (MessageSent != null) MessageSent(message);
        }

        public void Subscribe(MessageSentHandler<TMessage> handler)
        {
            MessageSent += handler;
        }

        public void Unsubscribe(MessageSentHandler<TMessage> handler)
        {
            MessageSent -= handler;
        }

        private event MessageSentHandler<TMessage> MessageSent;
    }
}
